<?php
ini_set("display_errors", 1);

// If you want to run the SabreDAV server in a custom location (using mod_rewrite for instance)
// You can override the baseUri here.
$baseUri = '/';

//Mapping PHP errors to exceptions
function exception_error_handler($errno, $errstr, $errfile, $errline ) 
{
	print "Error $errno [$errstr]; in $errfile at line $errline\n";
    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler");

require_once 'autoload.php';
require_once 'Sabre/autoload.php';

$uri = $_SERVER['REQUEST_URI'];
//print "Request uri = '$uri'";
//exit;
Slash_Debug::debug("Request uri = '$uri'"); 
//Set up the server
$config = new Slash_Config();
$cdserver = Slash_CalDAV_Server::getInstance();
$cdserver->configure($config);

//Add the ACL plugin
$aclPlugin = Slash_ACL_Plugin::getInstance();
//$authBackend = new Slash_DAV_Auth_Backend_BasicDAV($config);
$aclPlugin->configure($cdserver, $config, "Slash_DAV_Auth_Backend_BasicDAV");
$cdserver->addPlugin($aclPlugin);

//Add the lock plugin
$lockBackend = new Sabre_DAV_Locks_Backend_FS('data');
$lockPlugin = new Sabre_DAV_Locks_Plugin($lockBackend);
$cdserver->addPlugin($lockPlugin);				

// Support for html frontend
$browser = new Slash_Browser_Plugin();
$cdserver->addPlugin($browser);

//Add the CalDAV plugin
$caldavPlugin = new Slash_CalDAV_Plugin();
$cdserver->addPlugin($caldavPlugin);


// And off we go!
$cdserver->exec();

?>